#include <iostream>
using std::cout;
using std::endl;

class Data
{
public:
    Data(){
        cout << "Data()" << endl;
    }

    Data(int x)
    :_data(x)
    {}
    
    int getData()const{
        return _data;
    }

    ~Data(){
        cout << "~Data()" << endl;
    }

private:
    int _data = 10;
};

class MidderLayer{
public:
    MidderLayer(Data* p)
    :_pdata(p)
    {
        cout << "MidderLayer(Data*)" << endl;
    }

    Data* operator->(){
        return _pdata;
    }

    Data & operator*(){
        return *_pdata;
    }

    ~MidderLayer(){
        cout << "~MidderLayer()" << endl;
        if(_pdata){
            delete _pdata;
            _pdata = nullptr;
        }
        //cout << "~MidderLayer()" << endl;
    }
private:
    Data* _pdata;
};

void test0(){
    MidderLayer ml(new Data());
    cout << (ml.operator->())->getData() << endl;
    cout << ml->getData() << endl;

    cout << (ml.operator*()).getData() << endl;
    cout << (*ml).getData() << endl;
}

int main(int argc, char * argv[])
{
    test0();
    return 0;
}


